from django.db.models import CharField,DateTimeField,IntegerField,DateField,DecimalField,TextField,ForeignKey,BooleanField,DO_NOTHING,PROTECT
from apps.vadmin.op_drf.models import CoreModel

class Maintenances(CoreModel):
    asset = ForeignKey(to="assets.Assets",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="资产ID")
    supplier = ForeignKey(to="assets.Suppliers",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="供应商ID")
    asset_maintenance_type = CharField(max_length=128,null=True,verbose_name="维护类型")
    title = CharField(max_length=256, null=True, verbose_name="标题")
    is_warranty = BooleanField(null=False,default=0,verbose_name="是否保修")
    start_date = DateField(null=True,verbose_name="开始日期")
    completion_date = DateField(null=True, blank=True, verbose_name="完成日期")
    asset_maintenance_time = IntegerField(null=True, blank=True, verbose_name="维护时间,多少天")
    notes = TextField(null=True, blank=True, verbose_name="备注")
    cost = DecimalField(max_digits=20, decimal_places=2, null=True, blank=True, verbose_name="费用")
    deleted_datetime = DateTimeField(null=True, blank=True, verbose_name="删除时间")
    
    class Meta:
        verbose_name = '维护表'
        verbose_name_plural = verbose_name
        ordering = ['-id']  # 按id降序

    def __str__(self):
        return f"{self.title}"
